<?php
	include "../public/commom/config.php";
	include "../public/commom/commom.php";	
	
	if($_POST){
		$username = $_POST['username'];
		$password1 = $_POST['password1'];
		$password2 = $_POST['password1'];
		
		$sql1 = "SELECT * FROM user WHERE username = '$username'";
		
		$result1 = mysqli_query($conn, $sql1);
		
		$num = mysqli_num_rows($result1);
		
		if(!$num) {
			if($password1 == $password2) {
				$sql = "INSERT INTO user (username, password) VALUES ('$username', '$password1')";
			
				$result = mysqli_query($conn, $sql);
				
				mysqli_close($conn);
					
				header("Location: ./login.php");
			}else {
				echo "两次输入的密码不一致";
			}
		} else {
			echo "用户名已存在";
		}
	}
?>